package com.oocl.handlebatchdata.isgooddata;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class IsGoodData{
	
	public static boolean isGoodData(String[] data) {
		if(data.length!=5)return false;
		if(isGoodId(data[0])&&isGoodName(data[1])&&isGoodEmail(data[2])&&isGoodSex(data[3])&&isGoodBirthday(data[4]))
		{
			return true;
		}
		return false;
	}
	
	public static boolean isGoodId(String id){
//		String rc="^[0-9]{1,4}";
//		Pattern p =Pattern.compile(rc);
//		Matcher m =p.matcher(id);
//		return m.matches();
		return id.matches("^[0-9]{1,4}");
	}
	
	public static boolean isGoodName(String name){
//		String rc="[a-zA-Z]*";
//		Pattern p =Pattern.compile(rc);
//		Matcher m =p.matcher(name);
//		return m.matches();
		return name.matches("[a-zA-Z]*");
	}
	
	public static boolean isGoodEmail(String email){
//		String rc= "^\\w+@\\w+((\\.\\w{1,3}){1,2})";
//		Pattern p =Pattern.compile(rc);
//		Matcher m =p.matcher(email);
//		return m.matches();
		return email.matches("^\\w+@\\w+((\\.\\w{1,3}){1,2})");
	}
	
	public static boolean isGoodSex(String sex){
//		String rc="(true)|(false)";
//		Pattern p =Pattern.compile(rc);
//		Matcher m =p.matcher(sex);
//		return m.matches();
		return sex.matches("(true)|(false)");
	}
	
	public static boolean isGoodBirthday(String birth){
		String rc="((19\\d{2})|(200[0-9])|(201[0-7]))-([0?][1-9]|1[0-2])-([0?][1-9]|[1-2][0-9]|3[0-1])";
//		Pattern p =Pattern.compile(rc);
//		Matcher m =p.matcher(birth);
//		return m.matches();
		return birth.matches(rc);
	}
	
}
//String s="abcab+dcadcab,fadf,adfaf,aadfa=adf";
//String rc="[a-zA-Z0-9]";
//String r1="^[1-9]\\d{2}-\\d{2}-\\d{2}$";
//String r2="\\d{17}(\\d|X)";
//int count=0;
//Pattern p=Pattern.compile(rc);
//Matcher m=p.matcher(s);
//while(m.find())
//System.out.println(m.start()+"..."+m.end()+"..."+m.group());
//count++;
